/****** Object:  Stored Procedure [dbo].[v_DoanhThuSanPham] Script Date: 6/12/2012 ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'[dbo].v_DoanhThuSanPham') AND OBJECTPROPERTY(id, N'IsView') = 1)
	DROP VIEW [dbo].[v_DoanhThuSanPham]
Go

/******************************************************************************
**		Change History
*******************************************************************************
**		Date:		Author:					Description:
**		--------	--------				-----------------------------------
**		19/06/2012	SongTM					Innit created
*******************************************************************************/

create view v_DoanhThuSanPham
as
	select 
			px.SoPX, px.NgayXuatKho, px.SoHD, kh.TenKH, sp.MaThuoc, sp.TenHoatChat, 
			sp.TenBietDuoc, sp.QuyCach, dvt.TenDonVi, lk.SoLo, ctpx.DonGia, ctpx.SoLuong
	from 
			tbl_ChiTietPhieuNhap ctpn, tbl_SanPham sp, tbl_ChiTietPhieuXuat ctpx, tbl_luuKho lk,
			tbl_PhieuXuat px, tbl_PhieuGiaoHang pgh, tbl_KhachHang kh, tbl_DonViTinh dvt 
	where 
			ctpx.SoPX = px.SoPX and ctpx.MaLuuKho = lk.MaluuKho and lk.MaThuoc = sp.MaThuoc and 
			sp.MaDonVi = dvt.MaDonVi and kh.MaKH = pgh.MaKH and pgh.SoPX = px.SoPX
go